import request from '@/utils/request'

export function getRolesList () {
  return request(
    {
      url: '/roles',
      method: 'GET'
    }
  )
}

export function addUser (data) {
  return request(
    {
      method: 'POST',
      url: '/roles',
      data
    }
  )
}

export function editRoles (id) {
  return request(
    {
      url: `/roles/${id}`
    }
  )
}

export function editSubmitRoles (data) {
  return request(
    {
      url: `/roles/${data.roleId}`,
      method: 'PUT',
      data: {
        roleName: data.roleName,
        roleDesc: data.roleDesc
      }
    }
  )
}

export function removeEditRoles (id) {
  return request(
    {
      url: `/roles/${id}`,
      method: 'DELETE'
    }
  )
}

export function removeRightById (role, rightId) {
  return request(
    {
      url: `roles/${role.id}/rights/${rightId}`,
      method: 'DELETE'
    }
  )
}

export function allotRights (role, data) {
  return request(
    {
      url: `roles/${role}/rights`,
      method: 'POST',
      data: {
        rids: data
      }
    }
  )
}
